﻿#include "json_explain.h"
#include <QDebug>

Json_explain::Json_explain(QObject *parent) :
    QObject(parent)
{
}
/*解析运行就绪状态*/
bool Json_explain::explain_readyStatus(QString dataString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    QStringList nameList  = getJsonObjectNameString(dataString);
    if(nameList.size() == 2){
        parse_doucment = QJsonDocument::fromJson(dataString.toUtf8(), &json_error);
        if(json_error.error == QJsonParseError::NoError){
            jsonObject = parse_doucment.object();
        }
        if(jsonObject.contains(runFileCommand) && jsonObject.contains(runStateCommand)){
            QString value1 = jsonObject.value(runFileCommand).toString();
            int value2 = jsonObject.value(runFileCommand).toInt();
            if(value1.isEmpty() && value2 == 0){
//                qDebug()<<"ready1";
                return true;
            }
        }
    }else{
        return false;
    }
    return false;
}
/*解析运行界面*/
bool Json_explain::explain_runningstatus(QString dataString)
{
    QStringList nameList  = getJsonObjectNameString(dataString);
    if(nameList.size()>4){
        for(int i = 0 ; i <nameList.size(); i++){
            if(!order_runningstatusExplain(nameList.value(i),dataString)){
                return false;
            }
        }
    }else{
        return false;
    }
    return true;
}
/*运行界面信息查表*/
bool Json_explain::order_runningstatusExplain(QString commandString,QString dataString)
{
    if(commandString == x_CoordinateCommand){
        return explainCoordinateCommand(dataString, 0);
    }else if(commandString == y_CoordinateCommand){
        return explainCoordinateCommand(dataString, 1);
    }else if(commandString == z_CoordinateCommand){
        return explainCoordinateCommand(dataString, 2);
    }else if(commandString == u_CoordinateCommand){
        return explainCoordinateCommand(dataString, 3);
    }else if(commandString == limitAlarmCommand){
        return explainLimitAlarmCommand(dataString);
    }else if(commandString == checkLineNumCommand){
        return explainCheckLineNumCommand(dataString);
    }else if(commandString == currentSpeedCommand){
        return explainCurrentSpeedCommand(dataString);
    }else if(commandString == outPutCommand){
        return explainOutPutCommand(dataString);
    }else if(commandString == runTimeCommand){
        return explainRunTimeCommand(dataString);
    }else if(commandString == runStateCommand){
        return explainRunStateCommand(dataString);
    }
    return true;
}
/*查询行号*/
bool Json_explain::explainCheckLineNumCommand(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(checkLineNumCommand)){
        int value = jsonObject.value(checkLineNumCommand).toInt();
        dataMap[checkLineNumCommand] = type_valueKey(value);
//        qDebug()<<checkLineNumCommand<<value;
        return true;
    }
    return false;
}
/*当前速度*/
bool Json_explain::explainCurrentSpeedCommand(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(currentSpeedCommand)){
        int value = jsonObject.value(currentSpeedCommand).toInt();
        dataMap[currentSpeedCommand] = type_valueKey(value);
//        qDebug()<<currentSpeedCommand<<value;
        return true;
    }
    return false;
}
/*当前产量*/
bool Json_explain::explainOutPutCommand(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(outPutCommand)){
        int value = jsonObject.value(outPutCommand).toInt();
        dataMap[outPutCommand] = type_valueKey(value);
//        qDebug()<<outPutCommand<<value;
        return true;
    }
    return false;
}
/*运行时间*/
bool Json_explain::explainRunTimeCommand(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(runTimeCommand)){
        int value = jsonObject.value(runTimeCommand).toInt();
        dataMap[runTimeCommand] = type_valueKey(value);
//        qDebug()<<runTimeCommand<<value;
        return true;
    }
    return false;
}
/*运行状态*/
bool Json_explain::explainRunStateCommand(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(runStateCommand)){
        int value = jsonObject.value(runStateCommand).toInt();
        dataMap[runStateCommand] = type_valueKey(value);
//        qDebug()<<runStateCommand<<value;
        return true;
    }
    return false;
}
/*解析手动诊断信息*/
bool Json_explain::explain_manualDiagnose(QString dataString)
{
    QStringList nameList  = getJsonObjectNameString(dataString);
    if(nameList.size()>4){
        for(int i = 0 ; i <nameList.size(); i++){
            if(!order_manualDiagnoseExplain(nameList.value(i),dataString)){
                return false;
            }
        }
    }else{
        return false;
    }
    return true;
}
/*手动诊断信息查表*/
bool Json_explain::order_manualDiagnoseExplain(QString commandString,QString dataString)
{
    if(commandString == x_CoordinateCommand){
        return explainCoordinateCommand(dataString, 0);
    }else if(commandString == y_CoordinateCommand){
        return explainCoordinateCommand(dataString, 1);
    }else if(commandString == z_CoordinateCommand){
        return explainCoordinateCommand(dataString, 2);
    }else if(commandString == u_CoordinateCommand){
        return explainCoordinateCommand(dataString, 3);
    }else if(commandString == limitAlarmCommand){
        return explainLimitAlarmCommand(dataString);
    }
    return true;
}
/*查询坐标*/
bool Json_explain::explainCoordinateCommand(QString resultString, int axis)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    switch(axis){
    case 0://X
        if(jsonObject.contains(x_CoordinateCommand)){
            float value = jsonObject.value(x_CoordinateCommand).toDouble();
            dataMap[x_CoordinateCommand] = type_valueKey(value);
//            qDebug()<<x_CoordinateCommand<<value;
            return true;
        }
    case 1://y
        if(jsonObject.contains(y_CoordinateCommand)){
            float value = jsonObject.value(y_CoordinateCommand).toDouble();
            dataMap[y_CoordinateCommand] = type_valueKey(value);
//            qDebug()<<y_CoordinateCommand<<value;
            return true;
        }
    case 2://z
        if(jsonObject.contains(z_CoordinateCommand)){
            float value = jsonObject.value(z_CoordinateCommand).toDouble();
            dataMap[z_CoordinateCommand] = type_valueKey(value);
//            qDebug()<<z_CoordinateCommand<<value;
            return true;
        }
    case 3://u
        if(jsonObject.contains(u_CoordinateCommand)){
            float value = jsonObject.value(u_CoordinateCommand).toDouble();
            dataMap[u_CoordinateCommand] = type_valueKey(value);
//            qDebug()<<u_CoordinateCommand<<value;
            return true;
        }
    default:
        return false;
    }
    return false;
}
/*查询限位*/
bool Json_explain::explainLimitAlarmCommand(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(limitAlarmCommand)){
        int value = jsonObject.value(limitAlarmCommand).toInt();
        dataMap[limitAlarmCommand] = type_valueKey(value);
//        qDebug()<<limitAlarmCommand<<value;
        return true;
    }
    return false;
}
/*解析IO诊断信息*/
bool Json_explain::explain_IODiagnose(QString dataString)
{
    QStringList nameList  = getJsonObjectNameString(dataString);
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(dataString.toUtf8(), &json_error);
    if(json_error.error != QJsonParseError::NoError){
//        qDebug()<<"IODiagnose json error";
        return false;
    }
    jsonObject = parse_doucment.object();
    if(jsonObject.contains("DI")){
        QJsonArray DIArray = jsonObject.value("DI").toArray();
        QList<QMap<int,bool> > diList;
        for(int dinum = 0; dinum < DIArray.size(); dinum++){
            QJsonArray item = DIArray.at(dinum).toArray();
            QMap<int,bool> itemMap;
            itemMap.insert(item.at(0).toInt(),item.at(1).toBool());
            diList<<itemMap;
        }
        DIDOdiagnoseMap.insert("DI",diList);
    }
    if(jsonObject.contains("DO")){
        QJsonArray DOArray = jsonObject.value("DO").toArray();
        QList<QMap<int,bool> > doList;
        for(int donum = 0; donum < DOArray.size(); donum++){
            QJsonArray item = DOArray.at(donum).toArray();
            QMap<int,bool> itemMap;
            itemMap.insert(item.at(0).toInt(),item.at(1).toBool());
            doList<<itemMap;
        }
        DIDOdiagnoseMap.insert("DO",doList);
    }
    if(jsonObject.contains("AI")){
        QJsonArray AIArray = jsonObject.value("AI").toArray();
        QList<QMap<int,double> > aiList;
        for(int ainum = 0; ainum < AIArray.size(); ainum++){
            QJsonArray item = AIArray.at(ainum).toArray();
            QMap<int,double> itemMap;
            itemMap.insert(item.at(0).toInt(),item.at(1).toDouble());
            aiList<<itemMap;
        }
        AIAOdiagnoseMap.insert("AI",aiList);
    }
    if(jsonObject.contains("AO")){
        QJsonArray AOArray = jsonObject.value("AO").toArray();
        QList<QMap<int,double> > aoList;
        for(int aonum = 0; aonum < AOArray.size(); aonum++){
            QJsonArray item = AOArray.at(aonum).toArray();
            QMap<int,double> itemMap;
            itemMap.insert(item.at(0).toInt(),item.at(1).toDouble());
            aoList<<itemMap;
        }
        AIAOdiagnoseMap.insert("AO",aoList);
    }
//    qDebug()<<"DIDODiagnose"<<DIDOdiagnoseMap;
//    qDebug()<<"AIAODiagnose"<<AIAOdiagnoseMap;
    return true;
}
/*系统设置查表*/
bool Json_explain::explain_SystemSettingDataString(QString dataString)
{
    QStringList nameList  = getJsonObjectNameString(dataString);
    if(nameList.size()>2){
        for(int i = 0 ; i <nameList.size(); i++){
            if(!order_SystemSettingExplain(nameList.value(i),dataString)){
                return false;
            }
        }
    }else{
        return false;
    }
    return true;
}
/*系统设置解析*/
bool Json_explain::order_SystemSettingExplain(QString commandString,QString dataString)
{
    if(commandString == manualSpeedCommand){ //手动速度
        return explainManualSpeedCommand(dataString);
    }else if(commandString == backZeroSpeedCommand){ //回零速度
        return explainbackZeroSpeedCommand(dataString);

//    }else if(commandString == startBitCommand){ //启动位
//        return  explainStartBitCommand(dataString);
//    }else if(commandString.equals(AllCommand.stopBitCommand)){ //急停位
//        return  explainStopBitCommand(dataString);
//    }else if(commandString.equals(AllCommand.pauseBitCommand)){ //停止位
//        return  explainPauseBitCommand(dataString);
//    }else if(commandString.equals(AllCommand.ZeroBitCommand)){ //回零位
//        return  explainZeroBitCommand(dataString);
//    }else if(commandString.equals(AllCommand.glueBitCommand)){ //出胶位
//        return  explainGlueBitCommand(dataString);
//    }else if(commandString.equals(AllCommand.fogBitCommand)){ //雾化位
//        return  explainFogBitCommand(dataString);
//    }else if(commandString.equals(AllCommand.z_SafeHeightCommand)){ //安全高度
//        return  explainZ_SafeHeightCommand(dataString);
//    }else if(commandString.equals(AllCommand.needleHeightCommand)){ //抬针高度
//        return  explainNeedleHeightCommand(dataString);
//    }else if(commandString.equals(AllCommand.needleSpeedCommand)){ //抬针速度
//        return  explainNeedleSpeedCommand(dataString);
    }else if(commandString == backZeroCommand){ //自动回零
        return explainBackZeroCommand(dataString);
    }else if(commandString == glueFogCommand){ //出胶前雾化
        return explainGlueFogCommand(dataString);
    }else if(commandString == fogTimeCommand){ //雾化时间
        return explainFogTimeCommand(dataString);
    }else if(commandString == circulateCommand){ //循环启动
        return explainCirculateCommand(dataString);
    }else if(commandString == xLimCommand){ //限位方向
        return  explainLimitDisCommand(dataString, 0);
    }else if(commandString == yLimCommand){
        return  explainLimitDisCommand(dataString, 1);
    }else if(commandString == zLimCommand){
        return  explainLimitDisCommand(dataString, 2);
    }else if(commandString == uLimCommand){
        return  explainLimitDisCommand(dataString, 3);
    }else if(commandString == IO0_ReUseCommand){ //IO复用
        return  explainIO_ReUseCommand(dataString, 0);
    }else if(commandString == IO1_ReUseCommand){
        return  explainIO_ReUseCommand(dataString, 1);
    }else if(commandString == IO2_ReUseCommand){
        return  explainIO_ReUseCommand(dataString, 2);
    }else if(commandString == IO3_ReUseCommand){
        return  explainIO_ReUseCommand(dataString, 3);
    }else if(commandString == LimopCommand){
        return  explainLimopCommand(dataString);
    }
    return true;
}
/*回零速度*/
bool Json_explain::explainbackZeroSpeedCommand(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(backZeroSpeedCommand)){
        int value = jsonObject.value(backZeroSpeedCommand).toInt();
        dataMap[backZeroSpeedCommand] = type_valueKey(value);
//        qDebug()<<backZeroSpeedCommand<<value;
        return true;
    }
    return false;
}
/*手动速度*/
bool Json_explain::explainManualSpeedCommand(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(manualSpeedCommand)){
        int value = jsonObject.value(manualSpeedCommand).toInt();
        dataMap[manualSpeedCommand] = type_valueKey(value);
//        qDebug()<<manualSpeedCommand<<value;
        return true;
    }
    return false;
}
/*自动回零*/
bool Json_explain::explainBackZeroCommand(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(backZeroCommand)){
        int value = jsonObject.value(backZeroCommand).toBool();
        dataMap[backZeroCommand] = type_valueKey(value);
//        qDebug()<<backZeroCommand<<value;
        return true;
    }
    return false;
}
/*出胶前雾化*/
bool Json_explain::explainGlueFogCommand(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(glueFogCommand)){
        int value = jsonObject.value(glueFogCommand).toBool();
        dataMap[glueFogCommand] = type_valueKey(value);
//        qDebug()<<glueFogCommand<<value;
        return true;
    }
    return false;
}
/*雾化时间*/
bool Json_explain::explainFogTimeCommand(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(fogTimeCommand)){
        int value = jsonObject.value(fogTimeCommand).toInt();
        dataMap[fogTimeCommand] = type_valueKey(value);
//        qDebug()<<fogTimeCommand<<value;
        return true;
    }
    return false;
}
/*循环启动*/
bool Json_explain::explainCirculateCommand(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(circulateCommand)){
        QJsonArray tmpobj = jsonObject.value(circulateCommand).toArray();
        int value0 = tmpobj.at(0).toBool();
        int value1 = tmpobj.at(1).toInt();
        dataMap["circulateBool"] = type_valueKey(value0);
        dataMap[circulateCommand] = type_valueKey(value1);

//        qDebug()<<circulateCommand<<value0<<value1;
        return true;
    }
    return false;
}
/*限位方向*/
bool Json_explain::explainLimitDisCommand(QString resultString, int axis)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    switch(axis){
    case 0://X
        if(jsonObject.contains(xLimCommand)){
            int value = jsonObject.value(xLimCommand).toBool();
            dataMap[xLimCommand] = type_valueKey(value);
//            qDebug()<<xLimCommand<<value;
            return true;
        }
    case 1://y
        if(jsonObject.contains(yLimCommand)){
            int value = jsonObject.value(yLimCommand).toBool();
            dataMap[yLimCommand] = type_valueKey(value);
//            qDebug()<<yLimCommand<<value;
            return true;
        }
    case 2://z
        if(jsonObject.contains(zLimCommand)){
            int value = jsonObject.value(zLimCommand).toBool();
            dataMap[zLimCommand] = type_valueKey(value);
//            qDebug()<<zLimCommand<<value;
            return true;
        }
    case 3://u
        if(jsonObject.contains(uLimCommand)){
            int value = jsonObject.value(uLimCommand).toBool();
            dataMap[uLimCommand] = type_valueKey(value);
//            qDebug()<<uLimCommand<<value;
            return true;
        }
    default:
        return false;
    }
    return false;
}
/*IO复用*/
bool Json_explain::explainIO_ReUseCommand(QString resultString, int axis)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    switch(axis){
    case 0://X
        if(jsonObject.contains(IO0_ReUseCommand)){
            int value = jsonObject.value(IO0_ReUseCommand).toBool();
            dataMap[IO0_ReUseCommand] = type_valueKey(value);
//            qDebug()<<IO0_ReUseCommand<<value;
            return true;
        }
    case 1://y
        if(jsonObject.contains(IO1_ReUseCommand)){
            int value = jsonObject.value(IO1_ReUseCommand).toBool();
            dataMap[IO1_ReUseCommand] = type_valueKey(value);
//            qDebug()<<IO1_ReUseCommand<<value;
            return true;
        }
    case 2://z
        if(jsonObject.contains(IO2_ReUseCommand)){
            int value = jsonObject.value(IO2_ReUseCommand).toBool();
            dataMap[IO2_ReUseCommand] = type_valueKey(value);
//            qDebug()<<IO2_ReUseCommand<<value;
            return true;
        }
    case 3://u
        if(jsonObject.contains(IO3_ReUseCommand)){
            int value = jsonObject.value(IO3_ReUseCommand).toBool();
            dataMap[IO3_ReUseCommand] = type_valueKey(value);
//            qDebug()<<IO3_ReUseCommand<<value;
            return true;
        }
    default:
        return false;
    }
    return false;
}
/*限位方式*/
bool Json_explain::explainLimopCommand(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(LimopCommand)){
        int value = jsonObject.value(LimopCommand).toBool();
        dataMap[LimopCommand] = type_valueKey(value);
//        qDebug()<<LimopCommand<<value;
        return true;
    }
    return false;
}

/*运行设置查表*/
bool Json_explain::explain_MontionDataString(QString dataString)
{
    QStringList nameList  = getJsonObjectNameString(dataString);
    if(nameList.size()>2){
        for(int i = 0 ; i <nameList.size(); i++){
            if(!order_MontionSettingExplain(nameList.value(i),dataString)){
                return false;
            }
        }
    }else{
        return false;
    }
    return true;
}
/*运行设置解析*/
bool Json_explain::order_MontionSettingExplain(QString commandString,QString dataString)
{
    if(commandString == xDPRCommand){      //X每转位移
        return explainDPRCommand(dataString, 0);
    }else if(commandString == yDPRCommand){//Y每转位移
        return explainDPRCommand(dataString, 1);
    }else if(commandString == zDPRCommand){ //Z每转位移
        return explainDPRCommand(dataString, 2);
    }else if(commandString == uDPRCommand){ //U每转位移
        return explainDPRCommand(dataString, 3);
    }

    else if(commandString == xPPRCommand){ //X每转脉冲数
        return explainPPRCommand(dataString, 0);
    }else if(commandString == yPPRCommand){ //y每转脉冲数
        return explainPPRCommand(dataString, 1);
    }else if(commandString == zPPRCommand){ //z每转脉冲数
        return explainPPRCommand(dataString, 2);
    }else if(commandString == uPPRCommand){ //u每转脉冲数
        return explainPPRCommand(dataString, 3);
    }

    else if(commandString == x_BackZeroDirCommand){ //x回原点的方向
        return explainBackZeroDirCommand(dataString, 0);
    }else if(commandString == y_BackZeroDirCommand){ //y回原点的方向
        return explainBackZeroDirCommand(dataString, 1);
    }else if(commandString == z_BackZeroDirCommand){ //z回原点的方向
        return explainBackZeroDirCommand(dataString, 2);
    }else if(commandString == u_BackZeroDirCommand){ //u回原点的方向
        return explainBackZeroDirCommand(dataString, 3);
    }

    else if(commandString == x_MaxSpeedCommand){ //x最大速度
        return explainMaxSpeedCommand(dataString, 0);
    }else if(commandString == y_MaxSpeedCommand){ //y最大速度
        return explainMaxSpeedCommand(dataString, 1);
    }else if(commandString == z_MaxSpeedCommand){ //z最大速度
        return explainMaxSpeedCommand(dataString, 2);
    }else if(commandString == u_MaxSpeedCommand){ //u最大速度
        return explainMaxSpeedCommand(dataString, 3);
    }

    else if(commandString == x_AccelerateCommand){ //x加速时间
        return explain_AccelerateCommand(dataString, 0);
    }else if(commandString == y_AccelerateCommand){ //y加速时间
        return explain_AccelerateCommand(dataString, 1);
    }else if(commandString == z_AccelerateCommand){ //z加速时间
        return explain_AccelerateCommand(dataString, 2);
    }else if(commandString == u_AccelerateCommand){ //u加速时间
        return explain_AccelerateCommand(dataString, 3);
    }

    else if(commandString == x_MotorDirCommand){ //x电机方向
        return  explain_MotorDirCommand(dataString, 0);
    }else if(commandString == y_MotorDirCommand){ //y电机方向
        return  explain_MotorDirCommand(dataString, 1);
    }else if(commandString == z_MotorDirCommand){ //z电机方向
        return  explain_MotorDirCommand(dataString, 2);
    }else if(commandString == u_MotorDirCommand){ //u电机方向
        return  explain_MotorDirCommand(dataString, 3);
    }

    else if(commandString == xAddLimitDisCommand){ //x正向限位
        return  explainAddLimitDisCommand(dataString, 0);
    }else if(commandString == yAddLimitDisCommand){ //y正向限位
        return  explainAddLimitDisCommand(dataString, 1);
    }else if(commandString == zAddLimitDisCommand){ //z正向限位
        return  explainAddLimitDisCommand(dataString, 2);
    }else if(commandString == uAddLimitDisCommand){ //u正向限位
        return  explainAddLimitDisCommand(dataString, 3);
    }

    else if(commandString == xReduceLimitDisCommand){ //x负向限位
        return  explainReduceLimitDisCommand(dataString, 0);
    }else if(commandString == yReduceLimitDisCommand){ //y负向限位
        return  explainReduceLimitDisCommand(dataString, 1);
    }else if(commandString == zReduceLimitDisCommand){ //z负向限位
        return  explainReduceLimitDisCommand(dataString, 2);
    }else if(commandString == uReduceLimitDisCommand){ //u负向限位
        return  explainReduceLimitDisCommand(dataString, 3);
    }

    else if(commandString == rotationAxisCommand){ //旋转轴
        return explainRotationAxisCommand(dataString);
    }
    else if(commandString == axisStyleCommand){ //电机类型
        return  explainAxisStyleCommand(dataString);
    }
    else if(commandString == axisEnableCommand){ //电机使能
        return  explainAxisEnableCommand(dataString);
    }
    return true;
}
/*每转位移 解析*/
bool Json_explain::explainDPRCommand(QString resultString,int axis)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    switch(axis){
    case 0://X
        if(jsonObject.contains(xDPRCommand)){
            float value = jsonObject.value(xDPRCommand).toDouble();//X每转位移
            dataMap[xDPRCommand] = type_valueKey(value);
//            qDebug()<<xDPRCommand;
            return true;
        }
    case 1://y
        if(jsonObject.contains(yDPRCommand)){
            float value = jsonObject.value(yDPRCommand).toDouble();//X每转位移
            dataMap[yDPRCommand] = type_valueKey(value);
//            qDebug()<<yDPRCommand;
            return true;
        }
    case 2://z
        if(jsonObject.contains(zDPRCommand)){
            float value = jsonObject.value(zDPRCommand).toDouble();//X每转位移
            dataMap[zDPRCommand] = type_valueKey(value);
//            qDebug()<<zDPRCommand;
            return true;
        }
    case 3://u
        if(jsonObject.contains(uDPRCommand)){
            float value = jsonObject.value(uDPRCommand).toDouble();//X每转位移
            dataMap[uDPRCommand] = type_valueKey(value);
//            qDebug()<<uDPRCommand;
            return true;
        }
    default:
        return false;
    }
    return false;
}
//每转脉冲数
bool Json_explain::explainPPRCommand(QString resultString,int axis)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    switch(axis){
    case 0://X
        if(jsonObject.contains(xPPRCommand)){
            float value = jsonObject.value(xPPRCommand).toDouble();//X每转位移
            dataMap[xPPRCommand] = type_valueKey(value);
//            qDebug()<<xPPRCommand;
            return true;
        }
    case 1://y
        if(jsonObject.contains(yPPRCommand)){
            float value = jsonObject.value(yPPRCommand).toDouble();//X每转位移
            dataMap[yPPRCommand] = type_valueKey(value);
//            qDebug()<<yPPRCommand;
            return true;
        }
    case 2://z
        if(jsonObject.contains(zPPRCommand)){
            float value = jsonObject.value(zPPRCommand).toDouble();//X每转位移
            dataMap[zPPRCommand] = type_valueKey(value);
//            qDebug()<<zPPRCommand;
            return true;
        }
    case 3://u
        if(jsonObject.contains(uPPRCommand)){
            float value = jsonObject.value(uPPRCommand).toDouble();//X每转位移
            dataMap[uPPRCommand] = type_valueKey(value);
//            qDebug()<<uPPRCommand;
            return true;
        }
    default:
        return false;
    }
    return false;
}
/*回原点的方向*/
bool Json_explain::explainBackZeroDirCommand(QString resultString,int axis)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    type_valueKey tv;
    switch(axis){
    case 0://X
        if(jsonObject.contains(x_BackZeroDirCommand)){
            bool value = jsonObject.value(x_BackZeroDirCommand).toBool();
            dataMap[x_BackZeroDirCommand] = tv.setBool(value);
//            qDebug()<<x_BackZeroDirCommand;
            return true;
        }
    case 1://y
        if(jsonObject.contains(y_BackZeroDirCommand)){
            bool value = jsonObject.value(y_BackZeroDirCommand).toBool();
            dataMap[y_BackZeroDirCommand] = tv.setBool(value);
//            qDebug()<<y_BackZeroDirCommand;
            return true;
        }
    case 2://z
        if(jsonObject.contains(z_BackZeroDirCommand)){
            bool value = jsonObject.value(z_BackZeroDirCommand).toBool();
            dataMap[z_BackZeroDirCommand] = tv.setBool(value);
//            qDebug()<<z_BackZeroDirCommand;
            return true;
        }
    case 3://u
        if(jsonObject.contains(u_BackZeroDirCommand)){
            bool value = jsonObject.value(u_BackZeroDirCommand).toBool();
            dataMap[u_BackZeroDirCommand] = tv.setBool(value);
//            qDebug()<<u_BackZeroDirCommand;
            return true;
        }
    default:
        return false;
    }
    return false;
}
/*最大速度*/
bool Json_explain::explainMaxSpeedCommand(QString resultString,int axis)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    switch(axis){
    case 0://X
        if(jsonObject.contains(x_MaxSpeedCommand)){
            float value = jsonObject.value(x_MaxSpeedCommand).toDouble();
            dataMap[x_MaxSpeedCommand] = type_valueKey(value);
//            qDebug()<<x_MaxSpeedCommand;
            return true;
        }
    case 1://y
        if(jsonObject.contains(y_MaxSpeedCommand)){
            float value = jsonObject.value(y_MaxSpeedCommand).toDouble();
            dataMap[y_MaxSpeedCommand] = type_valueKey(value);
//            qDebug()<<y_MaxSpeedCommand;
            return true;
        }
    case 2://z
        if(jsonObject.contains(z_MaxSpeedCommand)){
            float value = jsonObject.value(z_MaxSpeedCommand).toDouble();
            dataMap[z_MaxSpeedCommand] = type_valueKey(value);
//            qDebug()<<z_MaxSpeedCommand;
            return true;
        }
    case 3://u
        if(jsonObject.contains(u_MaxSpeedCommand)){
            float value = jsonObject.value(u_MaxSpeedCommand).toDouble();
            dataMap[u_MaxSpeedCommand] = type_valueKey(value);
//            qDebug()<<u_MaxSpeedCommand;
            return true;
        }
    default:
        return false;
    }
    return false;
}
/*加速时间*/
bool Json_explain::explain_AccelerateCommand(QString resultString,int axis)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    switch(axis){
    case 0://X
        if(jsonObject.contains(x_AccelerateCommand)){
            float value = jsonObject.value(x_AccelerateCommand).toDouble();
            dataMap[x_AccelerateCommand] = type_valueKey(value);
//            qDebug()<<x_AccelerateCommand;
            return true;
        }
    case 1://y
        if(jsonObject.contains(y_AccelerateCommand)){
            float value = jsonObject.value(y_AccelerateCommand).toDouble();
            dataMap[y_AccelerateCommand] = type_valueKey(value);
//            qDebug()<<y_AccelerateCommand;
            return true;
        }
    case 2://z
        if(jsonObject.contains(z_AccelerateCommand)){
            float value = jsonObject.value(z_AccelerateCommand).toDouble();
            dataMap[z_AccelerateCommand] = type_valueKey(value);
//            qDebug()<<z_AccelerateCommand;
            return true;
        }
    case 3://u
        if(jsonObject.contains(u_AccelerateCommand)){
            float value = jsonObject.value(u_AccelerateCommand).toDouble();
            dataMap[u_AccelerateCommand] = type_valueKey(value);
//            qDebug()<<u_AccelerateCommand;
            return true;
        }
    default:
        return false;
    }
    return false;
}
/*电机方向*/
bool Json_explain::explain_MotorDirCommand(QString resultString,int axis)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    type_valueKey tv;
    switch(axis){
    case 0://X
        if(jsonObject.contains(x_MotorDirCommand)){
            bool value = jsonObject.value(x_MotorDirCommand).toBool();
            dataMap[x_MotorDirCommand] = tv.setBool(value);
//            qDebug()<<x_MotorDirCommand<<value;
            return true;
        }
    case 1://y
        if(jsonObject.contains(y_MotorDirCommand)){
            bool value = jsonObject.value(y_MotorDirCommand).toBool();
            dataMap[y_MotorDirCommand] = tv.setBool(value);
//            qDebug()<<y_MotorDirCommand<<value;
            return true;
        }
    case 2://z
        if(jsonObject.contains(z_MotorDirCommand)){
            bool value = jsonObject.value(z_MotorDirCommand).toBool();
            dataMap[z_MotorDirCommand] = tv.setBool(value);
//            qDebug()<<z_MotorDirCommand<<value;
            return true;
        }
    case 3://u
        if(jsonObject.contains(u_MotorDirCommand)){
            bool value = jsonObject.value(u_MotorDirCommand).toBool();
            dataMap[u_MotorDirCommand] = tv.setBool(value);
//            qDebug()<<u_MotorDirCommand<<value;
            return true;
        }
    default:
        return false;
    }
    return false;
}
/*正向限位*/
bool Json_explain::explainAddLimitDisCommand(QString resultString,int axis)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    switch(axis){
    case 0://X
        if(jsonObject.contains(xAddLimitDisCommand)){
            float value = jsonObject.value(xAddLimitDisCommand).toDouble();
            dataMap[xAddLimitDisCommand] = type_valueKey(value);
//            qDebug()<<xAddLimitDisCommand<<value;
            return true;
        }
    case 1://y
        if(jsonObject.contains(yAddLimitDisCommand)){
            float value = jsonObject.value(yAddLimitDisCommand).toDouble();
            dataMap[yAddLimitDisCommand] = type_valueKey(value);
//            qDebug()<<yAddLimitDisCommand<<value;
            return true;
        }
    case 2://z
        if(jsonObject.contains(zAddLimitDisCommand)){
            float value = jsonObject.value(zAddLimitDisCommand).toDouble();
            dataMap[zAddLimitDisCommand] = type_valueKey(value);
//            qDebug()<<zAddLimitDisCommand<<value;
            return true;
        }
    case 3://u
        if(jsonObject.contains(uAddLimitDisCommand)){
            float value = jsonObject.value(uAddLimitDisCommand).toDouble();
            dataMap[uAddLimitDisCommand] = type_valueKey(value);
//            qDebug()<<uAddLimitDisCommand<<value;
            return true;
        }
    default:
        return false;
    }
    return false;
}
/*负向限位*/
bool Json_explain::explainReduceLimitDisCommand(QString resultString,int axis)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    switch(axis){
    case 0://X
        if(jsonObject.contains(xReduceLimitDisCommand)){
            float value = jsonObject.value(xReduceLimitDisCommand).toDouble();
            dataMap[xReduceLimitDisCommand] = type_valueKey(value);
//            qDebug()<<xReduceLimitDisCommand;
            return true;
        }
    case 1://y
        if(jsonObject.contains(yReduceLimitDisCommand)){
            float value = jsonObject.value(yReduceLimitDisCommand).toDouble();
            dataMap[yReduceLimitDisCommand] = type_valueKey(value);
//            qDebug()<<yReduceLimitDisCommand;
            return true;
        }
    case 2://z
        if(jsonObject.contains(zReduceLimitDisCommand)){
            float value = jsonObject.value(zReduceLimitDisCommand).toDouble();
            dataMap[zReduceLimitDisCommand] = type_valueKey(value);
//            qDebug()<<zReduceLimitDisCommand;
            return true;
        }
    case 3://u
        if(jsonObject.contains(uReduceLimitDisCommand)){
            float value = jsonObject.value(uReduceLimitDisCommand).toDouble();
            dataMap[uReduceLimitDisCommand] = type_valueKey(value);
//            qDebug()<<uReduceLimitDisCommand;
            return true;
        }
    default:
        return false;
    }
    return false;
}
/*旋转轴*/
bool Json_explain::explainRotationAxisCommand(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(rotationAxisCommand)){  //解析
        int value =jsonObject.value(rotationAxisCommand).toInt();
        dataMap[rotationAxisCommand] = type_valueKey(value);
//        qDebug()<<rotationAxisCommand;
        return true;
    }
    return false;
}
/*电机类型*/
bool Json_explain::explainAxisStyleCommand(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(axisStyleCommand)){  //解析
        int value =jsonObject.value(axisStyleCommand).toInt();
        dataMap[axisStyleCommand] = type_valueKey(value);
//        qDebug()<<axisStyleCommand<<value;
        return true;
    }
    return false;
}
/*电机使能*/
bool Json_explain::explainAxisEnableCommand(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(axisEnableCommand)){  //解析
        int value =jsonObject.value(axisEnableCommand).toInt();
        dataMap[axisEnableCommand] = type_valueKey(value);
//        qDebug()<<axisEnableCommand<<value;
        return true;
    }
    return false;
}
/*获取轴电机*/
QVector<bool> Json_explain::getAxisSetting(int num)
{
    QVector<bool> tempValue(4,false);
    for(int i = 0 ; i < 4 ; i ++){
        int temp = num & 0x01;
        if(temp == 1){
            tempValue.replace(i, true);
        }else{
            tempValue.replace(i, false);
        }
        num = num >> 1;
    }
    return tempValue;
}
/*获取限位表*/
QVector<QVector<bool> > Json_explain::getAllLimit(int num)
{
    QVector<QVector<bool> > tmpValue;
    bool value = false;
    for(int i = 0 ; i < 4 ; i ++){
        QVector<bool> tmp;
        for(int j = 0 ; j < 4 ; j ++){
            int temp = num & 0x01;
            if(temp == 1){
                value = true;
            }else{
                value = false;
            }
            tmp<<value;
            num = num >> 1;
        }
        tmpValue<<tmp;
        tmp.clear();
    }
    return tmpValue;
}

/*Reply命令解析*/
bool Json_explain::explainReply(QString resultString)
{
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(resultString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }
    if(jsonObject.contains(replyCommand)){
        QString get = jsonObject.value(replyCommand).toString();
        if(get == "OK"){
            return true;
        }
    }
    return false;
}

/*获取命令列表*/
QStringList Json_explain::getJsonObjectNameString(QString dataString)
{
    QStringList null;
    QJsonObject jsonObject;
    QJsonParseError json_error;
    QJsonDocument parse_doucment;
    parse_doucment = QJsonDocument::fromJson(dataString.toUtf8(), &json_error);
    if(json_error.error == QJsonParseError::NoError){
        jsonObject = parse_doucment.object();
    }else{
        return null;
    }
    return jsonObject.keys();
}
